package aceona.api.weibo.sina;

import java.io.IOException;

import org.jsoup.nodes.Document;

import aceona.api.weibo.sina.connector.DocumentConnector;
import aceona.api.weibo.sina.impl.SinaDocParser;

public class SinaScanner {
	private static DocumentConnector connector = null;
	public static void main(String[] args) {
		SinaScanner scanner = new SinaScanner();
		scanner.scan3G();
	}
	
	public boolean scan3G(){
		String rootUrl = "http://weibo.cn/ducter?gsid=3_5bc17bbf872d995a7aff0f7c13f6130871";
//		String rootUrl = "http://weibo.cn/kaifulee?vt=4&gsid=3_5bc17bbf872d995a7aff0f7c13f6130871";
		try {
			if(connector == null){
				connector = new DocumentConnector();
			}
			Document rootDoc = connector.getDocument(rootUrl);
			this.docParser(rootDoc);
			//System.out.println(rootDoc.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return false;
	}
	/*
	public boolean scan(@SuppressWarnings("all") Map param){
		String searchDepth = (String)param.get("searchDepth");
		String searchUrl = (String)param.get("searchUrl");
		String extend = (String)param.get("extend");
		String extendDepth = (String)param.get("extendDepth");
		try {
			Document rootDoc = Jsoup.connect(searchUrl).get();
			File Root = new File(baseDir);
			if(!Root.exists() && !Root.isDirectory()){
				Root.mkdirs();
			}
			System.out.println(rootDoc.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return false;
	}*/
	
	private void docParser(Document doc) throws IOException{
		String weiboDomain = SinaScannerConsts.getProperty("sina.weibo.domain");
		String infoUrl_top = "";//顶层基本资料url
		String followUrl_top = "";//顶层关注url
		String fansUrl_top = "";//顶层粉丝url
		
		Parser parser = new SinaDocParser();//创建文档解析器
		parser.setDocument(doc);//设置需要解析的文档
		
		infoUrl_top = parser.urlParser(SinaScannerConsts.getProperty("sina.weibo.baseinfo"),"资料");
		followUrl_top = parser.urlParser(SinaScannerConsts.getProperty("sina.weibo.fans"),"关注");
		fansUrl_top = parser.urlParser(SinaScannerConsts.getProperty("sina.weibo.fans"),"粉丝");
		Document docInfo = connector.getDocument(weiboDomain+infoUrl_top);
		parser.setDocument(docInfo);
		parser.baseInfoParser();
//		System.out.println("资料url:  "+followUrl_top.toString());
//		System.out.println("粉丝url:  "+fansUrl_top.toString());
//		System.out.println("资料url:  "+infoUrl_top.toString());
//		System.out.println(baseinfo.toString());//打印doc全文
	}

}
